'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url user/pub/ttlogin 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			code,
			appid
		} = data;

		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		let appInfo = await db.collection('a_appid').where({
			appid: appid
		}).get()
		let appsecret = appInfo.data[0].appsecret
		const resData = await uniCloud.httpclient.request(
			'https://developer.toutiao.com/api/apps/v2/jscode2session', {
				method: 'POST',
				data: {
					code: code, //上面获取到的用户的code
					appid: appid, //小程序的AppID
					secret: appsecret //小程序的AppSecret
				},
				contentType: 'json', // 指定以application/json发送data内的数据
				dataType: 'json' // 指定返回值为json格式，自动进行parse
			})
		res.openid = resData.data.data.openid

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}